/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       texture.h
 * Author:     karooolek
 * Created on: 2009-03-14
 *
 **********************************************************************************************************************/

#ifndef TEXTURE_H_
#define TEXTURE_H_

#include "texturetype.h"
#include "cubetextureface.h"
#include "texturefiltering.h"
#include "texturewrapping.h"
#include "image.h"
#include "glee.h"

namespace mGameEngine
{
namespace Graphics
{

/**
 * Texture object.
 * Texture can be one dimensional, two dimensional,
 * three dimensional or cube type.
 * The type can't be set explicitly, it's set during construction.
 * Each texture has wrapping and filtering mode.
 */
class Texture
{
protected:
    /**
     * Texture object identifier
     */
    uint _id;

    /**
     * Type
     */
    TextureType _type;

    /**
     * Wrapping mode.
     */
    TextureWrapping _wrap;

    /**
     * Filtering mode
     */
    TextureFiltering _filter;

    /**
     * Cube texture active face.
     */
    CubeTextureFace _face;

public:
    /**
     * Create new empty texture.
     */
    Texture();

    /**
     * Create two dimensional texture from image.
     * @param image source image.
     * @param wrap wrapping mode.
     * @param filter filtering mode.
     */
    Texture(const Image *image, TextureWrapping wrap = TEX_WRAP_REPEAT, TextureFiltering filter = TEX_FILTER_NEAREST);

    /**
     * Create cube texture from six images.
     * @param positiveXimage positive X face image.
     * @param negativeXimage negative X face image.
     * @param positiveYimage positive Y face image.
     * @param negativeYimage negative Y face image.
     * @param positiveZimage positive Z face image.
     * @param negativeZimage negative Z face image.
     * @param wrap wrapping mode.
     * @param filter filtering mode.
     */
    Texture(const Image *positiveXimage, const Image *negativeXimage,
            const Image *positiveYimage, const Image *negativeYimage,
            const Image *positiveZimage, const Image *negativeZimage,
            TextureWrapping wrap = TEX_WRAP_REPEAT, TextureFiltering filter = TEX_FILTER_NEAREST);

    /**
     * Destroy texture.
     */
    virtual ~Texture();

    /**
     * Get texture type.
     * @return texture type.
     */
    TextureType getType() const
    {
        return _type;
    }

    /**
     * Get texture wrapping mode
     * @return texture wrapping mode
     */
    TextureWrapping getWrappingMode() const
    {
        return _wrap;
    }

    /**
     * Set texture wrapping mode.
     * @param wrap wrapping mode
     */
    void setWrappingMode(TextureWrapping wrap)
    {
        _wrap = wrap;
    }

    /**
     * Get texture filtering mode
     * @return texture filtering mode
     */
    TextureFiltering getFilteringMode() const
    {
        return _filter;
    }

    /**
     * Set texture filtering mode.
     * @param filter filtering mode
     */
    void setFilteringMode(TextureFiltering filter)
    {
        _filter = filter;
    }

    /**
     * Get cube texture active face.
     * @return cube texture active face.
     */
    CubeTextureFace getActiveFace()
    {
        return _face;
    }

    /**
     * Set cube texture active face.
     * @return cube texture active face.
     */
    void setActiveFace(CubeTextureFace face)
    {
        _face = face;
    }

    /**
     * Set texture image.
     * This method is used for two dimensional and cube textures.
     * @param image source image.
     */
    virtual void setImage(const Image *image);

    /**
     * Bind texture to texture mapping unit.
     * @param texUnit texture mapping unit identifier from 0 to 31.
     */
    virtual void bind(uint8 texUnit) const;
};

}
}

#endif // TEXTURE_H_
